package com.dashanchessgame.gameui;

import com.dashanchessgame.chess.*;

import java.awt.*;
import java.util.HashMap;

/**
 * @author 37460
 */
public class ChessManager {
    HashMap<Integer, Chess> chessEs = new HashMap<>();


    Chess[][] Chess ={};

    public ChessManager() {


        //兵
        ChessArms chessArms = new ChessArms();
        chessEs.put(chessArms.getType(), chessArms);

//        Chess[][] Chess ={{棋子},{棋子},{棋子}};
        //炮
        ChessCannon cannonChess = new ChessCannon();
        chessEs.put(cannonChess.getType(), cannonChess);

        //车
        ChessCar chessCar = new ChessCar();
        chessEs.put(chessCar.getType(), chessCar);

        //象
        ChessElephant chessElephant = new ChessElephant();
        chessEs.put(chessElephant.getType(), chessElephant);

        //将
        ChessCheckMate ChessCheckMate = new ChessCheckMate();
        chessEs.put(ChessCheckMate.getType(), ChessCheckMate);

        //马
        ChessHorse chessHorse = new ChessHorse();
        chessEs.put(chessHorse.getType(), chessHorse);

        //士
        ChessShi chessShi = new ChessShi();
        chessEs.put(chessShi.getType(), chessShi);
        //注册所有子类
    }

    public Chess getTheChess(int type) {
        if (type > 1000) {
            type -= 1000;
        }
        return chessEs.get(type);
    }

    HashMap<String, Image> imgMap = new HashMap<>();

    public void loadAllImage() {
        for (Chess c : chessEs.values()) {
            Image imgBlack = c.getImage(true);
            Image imgRed = c.getImage(false);

            imgMap.put(c.getType() + "_黑", imgBlack);
            imgMap.put(c.getType() + "_红", imgRed);
        }
    }

    public Image getImage(int type) {
        int color = type / 1000;
        type = type % 1000;

        return imgMap.get(type + (color == 1 ? "_黑" : "_红"));
    }
}
